package com.hzhjhh.view.manageView.menus.storage;

import java.awt.Frame;
import java.sql.*;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.BorderFactory;
import javax.swing.JTable;
import java.util.Vector;
import javax.swing.JScrollPane;
import javax.swing.table.JTableHeader;

import com.hzhjhh.init.dialog.Mytable;
import com.hzhjhh.means.Select_Means;
import com.hzhjhh.util.TimerScheduleTaskUtil;
import com.hzhjhh.view.manageView.menus.storage.constant.ShowConstants;
import com.hzhjhh.view.manageView.menus.storage.inOutStorage.BillEntry;
import com.hzhjhh.view.manageView.menus.storage.inOutStorage.DeleteBt;
import com.hzhjhh.view.manageView.menus.storage.inOutStorage.EnsureBt;
import com.hzhjhh.view.manageView.menus.storage.inOutStorage.MerchandiseCode;
import com.hzhjhh.view.manageView.menus.storage.inOutStorage.Num;
import com.hzhjhh.view.manageView.menus.storage.inOutStorage.PurchasePrice;
import com.hzhjhh.view.manageView.menus.storage.inOutStorage.ResetBt;
import com.hzhjhh.view.manageView.menus.storage.inOutStorage.SubmitBt;

import lombok.Getter;
import lombok.Setter;

import javax.swing.JButton;
import java.awt.Color;
import javax.swing.JOptionPane;
import java.awt.event.FocusEvent;
import java.awt.event.FocusAdapter;

/**
 * 菜单栏初始化-仓库-入库/出库-进/出货表弹出框
 * 
 * @author 12083
 *
 */
@Getter
@Setter
public class InOutTableDialog extends JDialog {
	Timestamp ts = new Timestamp(System.currentTimeMillis());
	JPanel panel1 = new JPanel();
	JLabel jLabel1 = new JLabel();
	JComboBox jComboBox1 = new JComboBox();
	JLabel jLabel2 = new JLabel();
	JTextField time = new JTextField();
	JLabel jLabel3 = new JLabel();
	JComboBox jComboBox2 = new JComboBox();
	JLabel jLabel4 = new JLabel();
	JLabel lbBillEntry = BillEntry.init();
	JLabel lbMerchandiseCode = MerchandiseCode.init();
	JTextField tfMerchandiseCode = new JTextField();
	JLabel lbNum = Num.init();
	JTextField jTextField3 = new JTextField();
	JLabel lbPurchasePrice = PurchasePrice.init();
	JTextField jTextField4 = new JTextField();
	JLabel jLabel9 = new JLabel();

	JTable jTable1 = new JTable();
	JTableHeader jTableHeader1 = jTable1.getTableHeader();

	Vector colnames1 = new Vector();
	Vector colnames2 = new Vector();

	JScrollPane jScrollPane1 = new JScrollPane();
	JButton btEnsure = EnsureBt.btInit(this);
	JButton btDelete = DeleteBt.btInit(this);
	JButton btReset = ResetBt.btInit(this);
	JButton btSubmit = SubmitBt.btInit(this);
	JTextField jTextField6 = new JTextField();
	JTextField jTextField7 = new JTextField();
	JLabel jLabel10 = new JLabel();
	JLabel jLabel11 = new JLabel();
	JLabel jLabel12 = new JLabel();

	public InOutTableDialog(Frame owner, String title, boolean modal) {
		super(owner, title, modal);
		try {
			setDefaultCloseOperation(DISPOSE_ON_CLOSE);
			jbInit();
			pack();
		} catch (Exception exception) {
			exception.printStackTrace();
		}
	}

	public InOutTableDialog() {
		this(new Frame(), "JoinAndExceed", false);
		this.setSize(665, 480);
		this.setVisible(true);
		this.setLocation(200, 100);
		this.setTitle("进/出货表");
	}

	private void jbInit() throws Exception {
		panel1.setLayout(null);
		this.getContentPane().setLayout(null);
		jLabel4.setBorder(BorderFactory.createEtchedBorder());
		jLabel4.setBounds(31, 7, 603, 36);
		tfMerchandiseCode.setBounds(131, 89, 130, 21);
		tfMerchandiseCode.addFocusListener(new Put_Out_Depot_jTextField2_focusAdapter(this));
		jTextField3.setBounds(343, 89, 72, 21);
		jTextField4.setBounds(503, 89, 84, 21);
		jLabel9.setBorder(BorderFactory.createEtchedBorder());
		jLabel9.setBounds(31, 82, 603, 58);
		jScrollPane1.setBounds(29, 150, 603, 248);

		this.getContentPane().setBackground(Color.pink);
		jTextField6.setEnabled(false);
		jTextField6.setBounds(343, 114, 72, 21);
		jTextField7.setBounds(503, 114, 83, 21);
		jLabel10.setText("仓 库 号：");
		jLabel10.setBounds(64, 114, 68, 15);
		jLabel11.setText("总金额：");
		jLabel11.setBounds(293, 114, 48, 15);
		jLabel12.setText("经 手 人：");
		jLabel12.setBounds(440, 114, 60, 15);
		TimerScheduleTaskUtil.time2Show(time);
		jComboBox3.setBounds(131, 114, 130, 21);
		this.getContentPane().add(panel1, null);
		jComboBox2.setBounds(488, 14, 94, 20);
		jLabel3.setText("制单人：");
		jLabel3.setBounds(426, 15, 59, 20);
		time.setBounds(280, 14, 131, 20);
		jLabel2.setText("时间：");
		jLabel2.setBounds(242, 14, 84, 20);
		jComboBox1.setBounds(134, 14, 84, 20);
		this.getContentPane().add(lbBillEntry);
		this.getContentPane().add(jScrollPane1);
		this.getContentPane().add(tfMerchandiseCode);
		this.getContentPane().add(jLabel12);
		this.getContentPane().add(lbPurchasePrice);
		this.getContentPane().add(jTextField6);
		this.getContentPane().add(jTextField3);
		this.getContentPane().add(lbNum);
		this.getContentPane().add(lbMerchandiseCode);
		this.getContentPane().add(jTextField4);
		this.getContentPane().add(jLabel11);
		this.getContentPane().add(jTextField7);
		this.getContentPane().add(jLabel10);
		this.getContentPane().add(jComboBox1);
		this.getContentPane().add(jComboBox2);
		this.getContentPane().add(jLabel3);
		this.getContentPane().add(time);
		this.getContentPane().add(jLabel2);
		this.getContentPane().add(jLabel1);
		this.getContentPane().add(jLabel4);
		this.getContentPane().add(btDelete);
		this.getContentPane().add(btEnsure);
		this.getContentPane().add(btReset);
		this.getContentPane().add(btSubmit);
		this.getContentPane().add(jComboBox3);
		this.getContentPane().add(jLabel9);
		jLabel1.setText("类别：");
		jLabel1.setBounds(98, 14, 84, 20);
		panel1.setBounds(0, 399, 1, 1);
		jComboBox1.addItem("入库");
		jComboBox1.addItem("出库");
		jComboBox2.addItem("郭健伟");
		jComboBox2.addItem("谭震欣");
		jComboBox2.addItem("徐敏");

		jComboBox3.addItem("CK0001");
		jComboBox3.addItem("CK0002");
		jComboBox3.addItem("CK0003");
		colnames2.add(colnames1);
		jTable1 = Mytable.maketable(colnames2, ShowConstants.IN_OUT_TABLE_HEAD_NAME); // 显示内容
		jScrollPane1.getViewport().add(jTable1); // 把表装入容器
	}

	Vector vector1 = new Vector();
	JComboBox jComboBox3 = new JComboBox();

	public void jTextField2_focusLost(FocusEvent e) {
		if (time.getText().length() != 0) {
			Vector select1 = Select_Means.Select_sort2(tfMerchandiseCode.getText());
			Vector select2 = new Vector();
			if (select1.size() == 0) {
				JOptionPane.showMessageDialog(this, "商品不存在", "错误", JOptionPane.ERROR_MESSAGE);
				return;
			} else {
				select2 = (Vector) select1.get(0);
				Double pice = new Double(select2.get(4).toString());
				double pice1 = ((int) (pice * 100)) / 100.0;
				Double pice2 = new Double(pice1);
				jTextField4.setText(pice2.toString()); // 单价
			}
		}

	}

}

class Put_Out_Depot_jTextField2_focusAdapter extends FocusAdapter {
	private InOutTableDialog adaptee;

	Put_Out_Depot_jTextField2_focusAdapter(InOutTableDialog adaptee) {
		this.adaptee = adaptee;
	}

	public void focusLost(FocusEvent e) {
		adaptee.jTextField2_focusLost(e);
	}
}


//class Put_Out_Depot_jButton4_actionAdapter implements ActionListener {
//	private InOutTableDialog adaptee;
//
//	Put_Out_Depot_jButton4_actionAdapter(InOutTableDialog adaptee) {
//		this.adaptee = adaptee;
//	}
//
//	public void actionPerformed(ActionEvent e) {
//		adaptee.jButton4_actionPerformed(e);
//	}
//}

// public void jComboBox1_actionPerformed(ActionEvent e) {
// String str=jComboBox1.getSelectedItem().toString();
// if(str.equals("入库")){
//
//
// }
// }
//
//
// }

// class Put_Out_Depot_jComboBox1_actionAdapter implements ActionListener {
// private Put_Out_Depot adaptee;
// Put_Out_Depot_jComboBox1_actionAdapter(Put_Out_Depot adaptee) {
// this.adaptee = adaptee;
// }

// public void actionPerformed(ActionEvent e) {
// adaptee.jComboBox1_actionPerformed(e);
// }
// }

// class Put_Out_Depot_jButton1_actionAdapter implements ActionListener {
// private Put_Out_Depot adaptee;
// Put_Out_Depot_jButton1_actionAdapter(Put_Out_Depot adaptee) {
// this.adaptee = adaptee;
// }
//
// public void actionPerformed(ActionEvent e) {
// adaptee.jButton1_actionPerformed(e);
// }
// }
// }